package com.rritw.webtools.common;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author zhyan
 */
public class CharsetEncodingFilter implements Filter {

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
                                                                                              ServletException {
        HttpServletResponse rsp = (HttpServletResponse) response;
        HttpServletRequest req = (HttpServletRequest) request;
        req.setCharacterEncoding(Const.CHARSET);
        rsp.setCharacterEncoding(Const.CHARSET);

        // rsp.setHeader("Pragma", "No-cache");
        // rsp.setHeader("Cache-Control", "no-cache");
        // rsp.setDateHeader("Expires", 0);
        chain.doFilter(request, response);
    }

    @Override
    public void destroy() {
    }

    @Override
    public void init(FilterConfig arg0) throws ServletException {

    }
}
